﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using YodaMaster.Models;

namespace YodaMaster.Models
{
    public class SchoolInitializer : DropCreateDatabaseAlways<SchoolContext>
    {
        protected override void Seed(SchoolContext context)
        {

            var enrollments = new List<Enrollment>
            {
                new Enrollment { StudentID = "1", ID = 1, Course_Name = "a", CourseID = 1, Grade = 1 },
                new Enrollment { StudentID = "1", ID = 1, Course_Name = "b",CourseID = 2, Grade = 3 },
                new Enrollment { StudentID = "1", ID = 1, Course_Name = "c", CourseID = 3, Grade = 1 },
                new Enrollment { StudentID = "2",ID = 2, Course_Name = "d", CourseID = 4, Grade = 2 },
                new Enrollment { StudentID = "2",ID = 2, Course_Name = "e", CourseID = 5, Grade = 4 },
                new Enrollment { StudentID = "2",ID = 2, Course_Name = "f", CourseID = 6, Grade = 4 },
                new Enrollment { StudentID = "3",ID = 3, Course_Name = "a", CourseID = 1            },
                new Enrollment { StudentID = "4",ID = 4, Course_Name = "a", CourseID = 1,           },
                new Enrollment { StudentID = "4", ID = 4, Course_Name = "b", CourseID = 2, Grade = 4 },
                new Enrollment { StudentID = "5", ID = 5, Course_Name = "c",CourseID = 3, Grade = 3 },
                new Enrollment { StudentID = "6", ID = 6, Course_Name = "d",CourseID = 4            },
                new Enrollment { StudentID = "7", ID = 7, Course_Name = "e",CourseID = 5, Grade = 2 },
            };
            enrollments.ForEach(s => context.Enrollments.Add(s));

            var students = new List<Student>
            {
                new Student { FirstMidName = "Carson",   LastName = "Alexander", StudentID = "1", Enrollments = (from c in enrollments.ToList() where c.ID == 1 select c).ToList() },
                new Student { FirstMidName = "Meredith", LastName = "Alonso",  StudentID = "2",  Enrollments = (from c in enrollments.ToList() where c.ID == 2 select c).ToList()   },
                new Student { FirstMidName = "Arturo",   LastName = "Anand",  StudentID = "3" ,   Enrollments = (from c in enrollments.ToList() where c.ID == 3 select c).ToList()   },
                new Student { FirstMidName = "Gytis",    LastName = "Barzdukas", StudentID = "4",   Enrollments = (from c in enrollments.ToList() where c.ID == 4 select c).ToList()   },
                new Student { FirstMidName = "Yan",      LastName = "Li",      StudentID = "5",   Enrollments = (from c in enrollments.ToList() where c.ID == 5 select c).ToList()    },
                new Student { FirstMidName = "Peggy",    LastName = "Justice", StudentID ="6" ,   Enrollments = (from c in enrollments.ToList() where c.ID == 6 select c).ToList()   },
                new Student { FirstMidName = "Laura",    LastName = "Norman",  StudentID = "7",   Enrollments = (from c in enrollments.ToList() where c.ID == 7 select c).ToList()   },
                new Student { FirstMidName = "Nino",     LastName = "Olivetto", StudentID = "8",  Enrollments = (from c in enrollments.ToList() where c.ID == 8 select c).ToList()  },
                 new Student { FirstMidName = "Admin",     LastName = "Admin", StudentID = "Admin",   },
            };
            students.ForEach(s => context.Students.Add(s));
            context.SaveChanges();

           


            var Users = new List<LoginModel>
            {
                new LoginModel {Username = "1", Password = "1234",},
                new LoginModel {Username = "2", Password = "4321",},
                new LoginModel {Username = "3", Password = "1111",},
                new LoginModel {Username = "4", Password = "1234",},
                new LoginModel {Username = "5", Password = "4321",},
                new LoginModel {Username = "6", Password = "1111",},
                new LoginModel {Username = "7", Password = "1234",},
                new LoginModel {Username = "8", Password = "4321",},
                
                new LoginModel {Username = "Admin", Password = "1111",},
            };
            Users.ForEach(s => context.Users.Add(s));
            context.SaveChanges();
        }
    }
}